package com.example.hdx.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.hdx.entity.Cart;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface CartMapper extends BaseMapper<Cart> {
    // 获取用户购物车列表（包含商品信息）
//    @Select("SELECT c.*, p.* FROM cart c " +
//            "LEFT JOIN products p ON c.product_id = p.id " +
//            "WHERE c.user_id = #{userId}")
    @Select({
            "SELECT",
            "c.id AS id,",
            "c.user_id AS userId,",
            "c.product_id AS productId,",
            "c.quantity AS quantity,",
            "c.selected AS selected,",
            "p.name AS name,",
            "p.price AS price,",
            "p.image AS image",
            "FROM cart c",
            "LEFT JOIN products p ON c.product_id = p.id",
            "WHERE c.user_id = #{userId}"
    })
    List<Cart> getCartWithProducts(@Param("userId") Long userId);
}